use crate::{model, utils};
use axum::{extract, response::Redirect, Json};
use rand::seq::SliceRandom;

pub async fn greet() -> &'static str {
    "Hello, World!"
}

pub async fn plain_text() -> &'static str {
    "foo"
}

pub async fn create_user(
    extract::Json(payload): extract::Json<model::CreateUser>,
) -> Json<model::User> {
    println!("{:?}", payload);
    Json(model::User { user: payload.user })
}

/// Random Image Url Redirect
pub async fn random_url() -> Redirect {
    let url_list = utils::read_url_list();
    let uri = url_list.choose(&mut rand::thread_rng()).unwrap();
    Redirect::temporary(uri)
}
